//
//  ShoppingCategory.m
//  EasyToo
//
//  Created by zhengzhe on 13-9-10.
//
//

#import "ShoppingCategory.h"

@implementation ShoppingCategory

- (id)initWithDictionary:(NSDictionary *)dict
{
    self = [self init];
    if (self) {
        self.categoryId = GetDictionaryStringDefaultNil(dict, @"id");
        self.name = GetDictionaryStringDefaultNil(dict, @"title");
        self.imageUrl = GetDictionaryStringDefaultNil(dict, @"cateimg");
        self.parentId = GetDictionaryStringDefaultNil(dict, @"parent_id");
        self.level = GetDictionaryStringDefaultNil(dict, @"level");
        
        NSArray *jsonArray = GetDictionaryArrayDefaultNil(dict, @"goods");
        if (jsonArray)
        {
            self.childCategorys = [[NSMutableArray alloc] init];
            
            for (int i = 0; i < [jsonArray count]; i++)
            {
                NSDictionary *jsonDict = [jsonArray objectAtIndex:i];
                ShoppingCategory *childCategory = [[ShoppingCategory alloc] initWithDictionary:jsonDict];
                [self.childCategorys addObject:childCategory];
                
                [childCategory release];
            }
        }
    }
    return self;
}

- (void)dealloc
{
    self.childCategorys = nil;
    [super dealloc];
}

@end
